package org.chw.rest;
/* *
 * @Author chen
 * @Date 2018/5/23 17:06
 */

import org.chw.model.Person;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/* *
 * @ClassName FirstRest
 * @Author chen
 * @Description 第一个rest服务
 * @Date 2018/5/23 17:06
 * @Version 1.0
 **/
@RestController
public class FirstRest {

    public static boolean canVisitDb = true;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Person getPerson(@PathVariable("id") int id, HttpServletRequest httpServletRequest) {
        Person person = new Person();
        person.setId(id);
        person.setName("chenhongwei");
        person.setMessage(httpServletRequest.getRequestURL().toString());
        return person;
    }

    @RequestMapping(value = "/db/{b}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean visitDB(@PathVariable boolean b) {
        canVisitDb = b;
        return canVisitDb;
    }
}
